Switch to immutable types and add typing.Final for constants per PEP 591#1360
Closed
sbobryshev wants to merge 1 commit intomodelcontextprotocol:mainfrom
Closed
Switch to immutable types and add typing.Final for constants per PEP 591#1360sbobryshev wants to merge 1 commit intomodelcontextprotocol:mainfrom
typing.Final for constants per PEP 591#1360sbobryshev wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
felixweinberger
requested changes
Sep 26, 2025
Contributor
felixweinberger
left a comment
There was a problem hiding this comment.
Hi @sbobryshev thank you for this suggestion.
I'm not sure these annotations add much value on variables that are already clearly intended as global variables by their CAPITAL_CASE. (FYI this PR also misses an instance in client/session.py)
While this ensures immutability of those constants, it's a lot of ceremony for relatively little gain. I'm open to it though if other maintainers strongly believe this adds value (cc: @Kludex @dsp-ant)
Member
|
This is technically correct, but I find this noisy. You can quickly merge or close it. It's up to you. 🤷♂️ |
Contributor
Same here - I'd prefer not introducing this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Switch to immutable types and add
typing.Finalfor constants per PEP 591Motivation and Context
Using immutable structures like tuples with Literal types allows for more precise type checking.
Instead of a generic
list[str], which only indicates a list of strings, the new approach infers specific literal values (e.g.,tuple[Literal['2024-11-05'], Literal['2025-03-26'], Literal['2025-06-18']]).How Has This Been Tested?
uv run pyrightTypes of changes
Checklist